package pl.put.miasi.agents;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.jbox2d.common.Vec2;
import org.jbox2d.common.XForm;

/**
 * Used for communication between players
 * @author root
 *
 */
public class Team {

	protected int number;
	protected List<PlayerAgent> agents;
	protected List<Vec2> positions;
	protected List<Integer> votes;
	public int score = 0;
	
	public Team(int number) {
		this.number = number;
		agents = new ArrayList<PlayerAgent>();
		positions = new ArrayList<Vec2>();
		votes = new ArrayList<Integer>();
	}
	
	/**
	 * Adds new player to team
	 * @param agent
	 * @param position
	 */
	public void registerPlayer(PlayerAgent agent, Vec2 position) {
		agents.add(agent);
		positions.add(position);
		votes.add(0);
	}
	
	/**
	 * Agent votes about his willingness to take ball
	 * @param agent
	 * @param vote
	 */
	public synchronized void vote(PlayerAgent agent, int vote) {
		//System.out.println(votes.size());
		for (int i = 0; i < agents.size(); i++) {
			if (agents.get(i).equals(agent)) {
				votes.set(i, vote);
			}
		}
	}
	
	
	/**
	 * Player informs about his position
	 * @param agent
	 * @param position
	 */
	public synchronized void setPosition(PlayerAgent agent, Vec2 position) {
		for (int i = 0; i < agents.size(); i++) {
			if (agents.get(i).equals(agent)) {
				positions.set(i, position);
			}
		}		
	}
	
	public synchronized List<Vec2> getPositions() {
		return Collections.unmodifiableList(positions);
	}
	
	public synchronized List<Integer> getVotes() {
		return Collections.unmodifiableList(votes);
	}
}
